﻿@model IEnumerable<WebUI.Models.Hospital>
@{
    string ID = ViewBag.QizItemID;
    var SelDepIDs = ViewBag.SelDeps as IEnumerable<string>;
}
@using (Ajax.BeginForm(new AjaxOptions()
{
    LoadingElementId = "OnLoadingSpan",
    UpdateTargetId = "SuiFangFormView",
    InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace,
    HttpMethod = "Post",
    OnSuccess = "$('#dialogbox').dialog('close');",
    OnFailure = "OnSiteError"
}))
{
    @Html.Hidden("ID")
    <div style="height: 450px; overflow: auto;">
        <ul id="hospitaltree">
            <li>
                <div>
                    请选择：</div>
                <ul>
                    @foreach (var h in Model)
                    {
                        <li class="closed">
                            <div class="tree-h"
                     title="[@Html.DisplayFor(m => h.HospCode) ] @Html.DisplayFor(m => h.HospStatusRef.OptionTitle)">
                                <strong>
                                    <input type="checkbox" name="selhospital" value="@(h.HospitalID)" id="h_@(h.HospitalID)" onchange="$('#h_@(h.HospitalID)_bs :checkbox').attr('checked',$(this).attr('checked'))" />
                                    <label for="h_@(h.HospitalID)">@h.HospName</label>
                                </strong>
                            </div>
                            @if (h.BingQus.Count > 0)
                            { 
                                <ul id="h_@(h.HospitalID)_bs">
                                    @foreach (var b in h.BingQus)
                                    {
                                        <li class="closed">
                                            <div class="tree-b">
                                                <strong>
                                                    <input type="checkbox" name="selbingqu" value="@(b.ID)" id="b_@(b.ID)" onchange="$('#b_@(b.ID)_deps :checkbox').attr('checked',$(this).attr('checked'))" />
                                                    <label for="b_@(b.ID)">@b.Title</label>
                                                </strong>
                                            </div>
                                            @if (b.Departments.Count > 0)
                                            { 
                                                <ul id="b_@(b.ID)_deps">
                                                    @foreach (var d in b.Departments)
                                                    {
                                                        <li>
                                                            <div class="tree-d">
                                                                <input @(SelDepIDs.Contains(d.DepartmentID) ? "checked='checked'" : "") type="checkbox" name="DepIDs" value="@(d.DepartmentID)" id="d_@(d.DepartmentID)" />
                                                                <label for="d_@(d.DepartmentID)">@d.DepName</label>
                                                            </div>
                                                        </li>
                                                    }
                                                </ul>
                                            }
                                        </li>
                                    }
                                </ul>
                            }
                        </li>
                    }
                </ul>
            </li>
        </ul>
    </div>
    <p>
        @Helpers.SubmitButton("确定")
    </p>
}
<script type="text/javascript">
    $(function () {
        $("#hospitaltree").treeview();
    });
</script>
